import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

def visualize_attacks(original, adversarial, labels):
    """可视化对抗样本特征分布"""
    tsne = TSNE(n_components=2)
    combined = np.vstack([original, adversarial])
    embedded = tsne.fit_transform(combined)
    
    plt.figure(figsize=(10, 6))
    plt.scatter(embedded[:len(original),0], embedded[:len(original),1], 
                c=labels, cmap='viridis', alpha=0.6, label='原始样本')
    plt.scatter(embedded[len(original):,0], embedded[len(original):,1], 
                c='red', marker='x', label='对抗样本')
    plt.title('对抗样本特征分布')
    plt.legend()
    plt.show() 